<template>
  <div class="login-container">
    <el-form
      v-show="true"
      :model="formdata"
      :rules="formrules"
      ref="LoginForm"
      label-position="left"
      label-width="0px"
      class="demo-ruleForm"
    >
      <h3 class="title">农产品交易管理系统</h3>
      <el-form-item prop="userMobile">
        <el-input type="text" v-model="formdata.userMobile" placeholder="账号/手机号"></el-input>
      </el-form-item>
      <el-form-item prop="userPassword">
        <el-input type="password" v-model="formdata.userPassword" placeholder="密码"></el-input>
      </el-form-item>
      <el-form-item style="width:100%;">
        <el-button
          type="primary"
          style="width:100%;"
          native-type="submit"
          @click.native.prevent="handleLogin()"
          :loading="logining"
        >登录</el-button>
      </el-form-item>
      <span><a href="#/register">用户注册</a></span>
      <!-- <span><a href="#/vip">会员注册</a></span>
        <span><a href="#/user">注册</a></span> -->
    </el-form>
  </div>
</template>

<script>
import constantRouterMap from "@/router";

export default {
  components: {},
  data() {
    return {
      logining: false,
      formdata: {
        userMobile: "",
        userPassword: "",
      },
      formrules: {
        userMobile: [{ required: true, message: "请输入账号", trigger: "blur" }],
        userPassword: [{ required: true, message: "请输入密码", trigger: "blur" }]
      },
    };
  },
  methods: {
    handleLogin() {
      this.$refs["LoginForm"].validate(valid => {
        if (valid) {
          this.logining = true;
          this.$store
            .dispatch("Login", this.formdata)
            .then(() => {
              this.$router.push({ path: "/mydesktop" });
              this.logining = false;
              this.$message.success('登录成功！');
            })
            .catch(() => {
              this.logining = false;
            });
        } else {
          return false;
        }
      });
    },
  }
};
</script>

<style lang="scss" scoped>
.login-container {
  position: relative;
  width: 100%;
  height: 100vh;
  overflow: hidden;
  
  // 背景图片样式
  background-image: url('../../assets/southeast.jpg'); // 替换为你的背景图片路径
  background-size: cover;
  background-position: center;
  
  .demo-ruleForm {
    position: relative;
    width: 350px;
    padding: 35px 35px 15px;
    margin: 180px auto;
    background: rgba(255, 255, 255, 0.9); // 半透明背景
    border-radius: 5px;
    box-shadow: 0 0 25px rgba(0, 0, 0, 0.1);
    z-index: 1;
  }

  .title {
    margin: 0 auto 40px;
    text-align: center;
    color: #303133;
  }
}
</style>